<?php
if (function_exists('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Bottom Sidebar',
		'description' => '底部边栏',
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => '</h2>',
	));
}
/**
 * pagenav
 **/
function yuguo_navi() {
  global $wp_query, $wp_rewrite;
  $pages = '';
  $max = $wp_query->max_num_pages;
  if (!$current = get_query_var('paged')) $current = 1;
  $a['base'] = ($wp_rewrite->using_permalinks()) ? user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' ) : @add_query_arg('paged','%#%');
  if( !empty($wp_query->query_vars['s']) ) $a['add_args'] = array( 's' => get_query_var( 's' ) );
  $a['total'] = $max;
  $a['current'] = $current;
  //custom pagenav
  $total = 0; //1 - display the text "Page N of N", 0 - not display
  $a['mid_size'] = 2; //how many links to show on the left and right of the current
  $a['end_size'] = 1; //how many links to show in the beginning and end
  $a['prev_text'] = '«'; //text of the "Previous page" link
  $a['next_text'] = '»'; //text of the "Next page" link
  $a['type'] = 'plain';
  if ($max > 1) echo '<div class="yuguo-pagenavi">';
  if ($total == 1 && $max > 1) $pages = '<span class="pages">Page ' . $current . ' of ' . $max . '</span>'."\r\n";
  echo $pages . paginate_links($a);
  if ($max > 1) echo '</div>';
}

function custom_comment_fun($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment; ?>
  <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div id="comment-<?php comment_ID(); ?>" class="comment-body">
      <?php echo get_avatar($comment,$size=$args['avatar_size']); ?>
      <div class="comment-head">
        <cite><?php comment_author_link(); ?></cite><span class="says">Says：</span>
      <?php if ($comment->comment_approved == '0') : ?>
      <em><?php _e('您的评论正在等待审核') ?></em>
      <?php endif; ?>
      <div class="comment-meta commentmetadata">
        <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php echo get_comment_date('Y M d');?> <?php echo get_comment_time();?></a>
        <?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','') ?>
      </div>
      </div>
      <?php comment_text(); ?>
      <div class="reply">
        <?php comment_reply_link(array_merge( $args, array('depth' => $depth,'reply_text' => '回复', 'max_depth' => $args['max_depth']))) ?>
      </div>
    </div>
   <?php
  // Do not include the </li> tag.
}

add_action( 'init', 'register_my_menus' );
/**
 * @return void
 * register the menu of the top
 */
function register_my_menus() {
register_nav_menus();
}

/*
Plugin Name: Google Analytics
Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/
Description: Enables <a href="http://www.google.com/analytics/">Google Analytics</a> on all pages.
Version: 1.0.2
Author: Kevin Sylvestre
Author URI: http://www.ksylvest.com/
*/

if (!defined('WP_CONTENT_URL'))
      define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
if (!defined('WP_CONTENT_DIR'))
      define('WP_CONTENT_DIR', ABSPATH.'wp-content');
if (!defined('WP_PLUGIN_URL'))
      define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins');
if (!defined('WP_PLUGIN_DIR'))
      define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');

function activate_googleanalytics() {
  add_option('web_property_id', 'UA-0000000-0');
  add_option('asynchronous_tracking', 'no');
}

function deactive_googleanalytics() {
  delete_option('web_property_id');
  delete_option('asynchronous_tracking');
}

function admin_init_googleanalytics() {
  register_setting('googleanalytics', 'web_property_id');
  register_setting('googleanalytics', 'asynchronous_tracking');
}

function admin_menu_googleanalytics() {
  add_submenu_page('themes.php','Google Analytics', 'Google Analytics', 8, 'googleanalytics', 'options_page_googleanalytics');
}

function options_page_googleanalytics() {
  include('options-googleanalytics.php');
}

function asynchronous_googleanalytics($web_property_id) {
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $web_property_id ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<?php
}

function synchronous_googleanalytics($web_property_id) {
?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("<?php echo $web_property_id ?>");
pageTracker._trackPageview();
} catch(err) {}</script>
<?php
}

function googleanalytics() {

  $web_property_id = get_option('web_property_id');
  $asynchronous_tracking = (get_option('asynchronous_tracking') == 'yes');

  switch($asynchronous_tracking) {
    case true:
      asynchronous_googleanalytics($web_property_id);
      break;
    case false:
      synchronous_googleanalytics($web_property_id);
      break;
  }

}

register_activation_hook(__FILE__, 'activate_googleanalytics');
register_deactivation_hook(__FILE__, 'deactive_googleanalytics');

if (is_admin()) {
  add_action('admin_init', 'admin_init_googleanalytics');
  add_action('admin_menu', 'admin_menu_googleanalytics');
}

if (!is_admin()) {
	add_action('wp_footer', 'googleanalytics');
}

/**
 * set the feature category id
 */
function activate_featureposts() {
  add_option('feature_post_category_id', '1');
}

function deactive_featureposts() {
  delete_option('feature_post_category_id');
}

register_activation_hook(__FILE__, 'activate_featureposts');
register_deactivation_hook(__FILE__, 'deactive_featureposts');

function admin_init_featureposts() {
  register_setting('featureposts', 'feature_post_category_id');
}

function admin_menu_featureposts() {
  add_submenu_page('themes.php','Feature Posts', 'Feature Posts', 8, 'featureposts', 'options_page_featureposts');
}

function options_page_featureposts() {
  include('options-feature-posts.php');
}

if (is_admin()) {
  add_action('admin_init', 'admin_init_featureposts');
  add_action('admin_menu', 'admin_menu_featureposts');
}

/**
 * set the doc's width
 */
function activate_docwidth() {
  add_option('doc_width_id', 'doc');
}

function deactive_docwidth() {
  delete_option('doc_width_id');
}

register_activation_hook(__FILE__, 'activate_docwidth');
register_deactivation_hook(__FILE__, 'deactive_docwidth');

function admin_init_docwidth() {
  register_setting('docwidth', 'doc_width_id');
}

function admin_menu_docwidth() {
  add_submenu_page('themes.php','Theme Width', 'Theme Width', 8, 'docwidth', 'options_page_docwidth');
}

function options_page_docwidth() {
  include('options-docwidth.php');
}

if (is_admin()) {
  add_action('admin_init', 'admin_init_docwidth');
  add_action('admin_menu', 'admin_menu_docwidth');
}
?>